package com.wly.mina.filter.handle;

import java.util.logging.Logger;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;

import com.wly.define.PacketDefine;
import com.wly.gpb.Login.LogIn;
import com.wly.gpb.Test.SendTest;
import com.wly.packet.CSLoginPacket;
import com.wly.packet.Packet;
import com.wly.packet.TestPacket;

public class GameServerHandle extends IoHandlerAdapter
{
	private static Logger log = Logger.getLogger("GameServerHandle");
	@Override
	public void messageReceived(IoSession session, Object message)
			throws Exception
	{
		// TODO Auto-generated method stub
		log.info("handel object:"+message.toString());
		System.out.println("handle "+message.toString());
		System.out.println(message instanceof Packet);
		if(message instanceof Packet)
		{
			Packet pkg = (Packet)message;
			switch(pkg.getPacketID())
			{
				case PacketDefine.WLY_PCKET_LOGIN:
					log.info("get login packet");
					CSLoginPacket login = (CSLoginPacket)pkg.content;
					LogIn loginPkg = (LogIn)login.content;
					System.out.println("get login paket: "+loginPkg.getPassword()+" "+loginPkg.getPassword());
					break;
				case 3:
					log.info("get test packet");
					TestPacket test = (TestPacket)pkg;
					SendTest sendTest = (SendTest)test.content;
					
					log.info("convert to TestPacket :"+sendTest.getName()+" "+sendTest.getPass());
					break;
				default:
					log.info("unkonw packet id");
					break;
			}
		}
		log.info("send message: "+message.toString());
		session.write(message);
	}
}
